<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of reloadtable
 *
 * @author dragon.hu add @2016.5.31
 */


class reloadtables_Controller Extends Controller {
	
	private $commandlist;
	
	function _init() 
	{
        check_level(50, segment(0), segment(1), segment(2, 'index'));
        
        $config = get_config();
        $this->commandlist = $config['inc']['gmcommand_list'];
	}
	
    //put your code here
    function index() {
        if (is_submit()) {
            $rowdata = $_POST;
            $arealist = $rowdata['areaIds'];
            $command = $rowdata['row']['command'];
            $command = $this->commandlist[$command];
            //var_dump($arealist);
            //var_dump($command);
            //exit();
            
            $area_host = get_area_list_url();
            $area_live_list = get_area_list_live();
            $areastr = "";
            if (in_array('0', $arealist))
            {
            	foreach ($area_live_list as $k => $w) {  //echo $k."***";
            		$strResult = vpost($area_host[$k] . "gm_command=$command" . "&action=31&operation=1", 2);
            		$areastr .= $k.',';
            	}
            }
            else
            {
            	foreach ($arealist as $k => $v)
            	{
            		if (isset($area_live_list[$v]))
            		{
            			//var_dump($area_host[$v]. "gm_command=$command" . "&action=31&operation=1");
            			//exit();
            			$strResult = vpost($area_host[$v]. "gm_command=$command" . "&action=31&operation=1", 2);
            			$areastr .= $v.',';
            		}
            	}
            }
            
           if(0 == $strResult)
           {
           		//echo 'success';
           		//cp_tips("success");
           		$operater = $this->auth->fields['username'];
           		insert_log(translate('MENU_SEAL_RELOADTALBES'), 'reload', NULL, array("info"=>"operater = $operater , gm_command = $command , area = $areastr"));
           		echo "<script>alert('".translate('C_TIPS_SUCCESS_TEXT')."')</script>";
           }
           else 
           {
           		//echo 'fail...';
           		//cp_tips("error");
           		echo "<script>alert('".translate('C_TIPS_ERROR_TEXT')."')</script>";
           }
        } 
	    //$this->view->assign("arealist", $this->form->select("row[area_host]", get_area_list_host(), '', array('id' => 'area_host')));
        set_area_list_view("arealist");
        $this->view->assign ("commandlist", $this->form->select ("row[command]", $this->commandlist, '', array('id' => 'command')));
	    $this->view->display("seal/reloadtables/index");
        
    }
}

?>
